# class Solution:
#     def wordPattern(self, pattern: str, s: str) -> bool:
#         words=s.split(" ")
#         mapper={}
#         if len(words) != len(pattern):
#             return False
#         for i,j in zip(pattern,words):
#             try:
#                 if mapper[i]!=j:
#                     return False
#             except KeyError:
#                 if j in mapper.values():
#                     return False
#                 mapper[i]=j
#         return True

'''
执行用时：
36 ms
, 在所有 Python3 提交中击败了
79.88%
的用户
内存消耗：
14.7 MB
, 在所有 Python3 提交中击败了
5.37%
的用户
'''

class Solution:
    def wordPattern(self, pattern: str, s: str) -> bool:
        words=s.split(" ")
        mapper={}
        rmapper={}
        if len(words) != len(pattern):
            return False
        for i,j in zip(pattern,words):
            try:
                if mapper[i]!=j:
                    print(1)
                    return False
            except KeyError:
                try:
                    temp=rmapper[j]==i
                    return False
                except KeyError:
                    mapper[i]=j
                    rmapper[j]=i
        return True

s=Solution()
print(s.wordPattern('abba',
"dog cat cat dog"))